'use strict';
module.exports = {
	/**
	 * 添加客户端推送标识
	 * @url client/push/pub/addPushClientId 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid, userId, pushClientId } = data;
		let res = { code: 0, msg: "success" };
		// 业务逻辑开始-----------------------------------------------------------
    const pushInfo = await vk.baseDao.findByWhereJson({
      dbName:"user-live-push",
      whereJson: {
        user_id: userId,
      }
    });

    try{
      if (pushInfo) {
        await vk.baseDao.updateById({
          dbName:"user-live-push",
          id: pushInfo._id,
          dataJson: {
            push_client_id: pushClientId
          }
        })
      } else {
        await vk.baseDao.add({
          dbName:"user-live-push",
          dataJson: {
            user_id: userId,
            push_client_id: pushClientId
          }
        })
      }
    }catch(e){
      //TODO handle the exception
      res = { code: -1, msg: 'push client id存储失败' }
    }


		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
